﻿ <!--header-->
{{include file="../Common/header"}}
	<!--/header-->
	<script type="text/javascript">
		$(function(){
		$('.shop-style-select a').click(function(){
			$(this).addClass('hover').siblings().removeClass('hover');
			//抓取div的个数
			var divLen=$('.shop-style-select').length;
			//抓取选中的a的个数
			var aLen=$('.shop-style-select .hover').length;
			//alert(aLen);
			if(divLen==aLen){
				var str='';
				$.each($('.shop-style-select .hover'), function() {
					str+=$(this).attr('gaid')+'|';
				});
				$.ajax({
					type:"post",
					url:"{{U('goodsList')}}",
					data:{gaids:str},
					dataType:'json',
					success:function(goodsList){
						var num='';
						var inventory='';
						if(goodsList){
							num+='<span>货号：</span>';
							num+='<span>'+goodsList.number+'</span>';
							inventory+='库存:';
							inventory+='<span class="inventory">'+goodsList.inventory+'</span>';
						}else{
							$('.name-money strong').html(({{$goodsData['shopprice']}}).toFixed(2));
							$('.name-money strong').attr('value',({{$goodsData['shopprice']}}).toFixed(2));
							inventory+='库存：<span class="inventory">0</span>';
						}
						$('.shop-name-title span').html(num);
						$('.shop-num span').html(inventory);
						money=(goodsList.add*1+{{$goodsData['shopprice']}}*1).toFixed(2);
						$('.name-money strong').html(money);
						$('.name-money strong').attr('value',money);
					}
				});
			}
		});
		//加入购物车
		$('.shop-name-buy .name-car').click(function(){
			//抓取div的个数
			var divLen=$('.shop-style-select').length;
			//抓取选中的a的个数
			var aLen=$('.shop-style-select .hover').length;
			//alert(aLen);
			if(divLen==aLen){
				//取出选择的货品组合
				var str='';
				$.each($('.shop-style-select .hover'), function() {
					str+=$(this).attr('gaid')+'|';
				});
				//取出当前的货品名称
				var name=$('.shop-name-title h1').html();
				//取出当前货品的单价
				var money=$('.name-money strong').html();
				//取出当前货品的库存
				var inventory=$(".shop-num .inventory").html();
				//取出购买数量
				var num=$('.shop-num .goodsNum').attr('value');
				if(inventory==0){
					alert('该货品已售完，请选择其他商品');
				}else{
					$.ajax({
						type:'post',
						url:"{{U('Cart/add')}}",
						data:{arr:{name:name,num:num,price:money,options:str,gid:{{$_GET['gid']}}}},
						dataType:'json',
						success:function(phpData){
							if(phpData.num){
								alert(phpData.massage);
								$('.cart-add span').html(phpData.num);
							}else{
								alert(phpData);
							}
						}
					});
					
				}
			}else{
				alert('请对产品类型进行选择');
			}
		});
	});
	
	</script>
	<!--center-->
	<div id="content">
		<div class="shop-main">
			<div class="shop-left">
				<div class="shop-img">
					{{foreach from="$detailData['dimg']" value="$v"}}
					<img src="{{$v}}" alt="" />
					{{endforeach}}
				</div>
				<div class="shop-bottom">
					{{foreach from="$detailData['dimg']" value="$v"}}
					<img src="{{$v}}" alt="" />
					{{endforeach}}
				</div>
			</div>
			<div class="shop-name">
				<div class="shop-name-title">
					<h1 name='gname'>{{$goodsData['gname']}}</h1>
					<span></span>
				</div>
				<div class="shop-name-money">
					<div class="name-money">单价：¥<strong name="shopEnd" value="{{$goodsData['shopprice']}}">{{$goodsData['shopprice']}}</strong></div>
					<div class="name-money">原价：<span style="text-decoration: line-through;">¥{{$goodsData['makertprice']}}</span></div>
				</div>
				
				<div class="shop-name-chenge">
					{{foreach  from="$fallTamp"  value="$f"}}
					<div class="shop-style-select">
						{{$f['name']}}：
						{{foreach from="$f['value']" value="$ff" }}
						<a href="javascript:;" gaid="{{$ff['gaid']}}">{{$ff['gavalue']}}</a>
						{{endforeach}}
					</div>
					{{endforeach}}
					<div class="shop-num">购买数量：
						<a href="javascript:;" class="del">-</a>
						<input type="text" class="goodsNum" value="1" readonly="readonly"/>
						<a href="javascript:;" class="add">+</a>
						<span></span>
					</div>
				<div class="save">服务：由<span>" 前沿科技商城 "</span>直接销售和发货，并提供售后服务</div>
				</div>
				<div class="shop-name-buy">
					<a href="javascript:;" class="name-car">加入购物车</a>
					<a href="javascript:;" class="name-buy">立即购买</a>
					<script type="text/javascript">
						$(function(){
							//立即购买，加入订单
							$('.name-buy').click(function(){
								//抓取div的个数
								var divLen=$('.shop-style-select').length;
								//抓取选中的a的个数
								var aLen=$('.shop-style-select .hover').length;
								//alert(aLen);
								if(divLen==aLen){
									//取出选择的货品组合
									var str='';
									$.each($('.shop-style-select .hover'), function() {
										str+=$(this).attr('gaid')+'|';
									});
									//取出当前的货品名称
									var name=$('.shop-name-title h1').html();
									//取出当前货品的单价
									var money=$('.name-money strong').html();
									//取出当前货品的库存
									var inventory=$(".shop-num .inventory").html();
									//取出购买数量
									var num=$('.shop-num .goodsNum').attr('value');
									var gid={{$_GET['gid']}};
									money=money*num;
									if(inventory==0){
										alert('该货品已售完，请选择其他商品');
									}else{
										$.ajax({
											type:"post",
											url:"{{U('Order/addOrder')}}",
											data:{orderData:{gototal:money,goallnum:num}},
											dataType:'json',
											success:function(goid){
												if(goid){
													$.ajax({
														type:"post",
														url:"{{U('Order/olist')}}",
														data:{goodsList:{shop_goodsorder_goid:goid,shop_goods_gid:gid,oltotal:money,olnum:num,options:str}},
														
														success:function(){
															window.location.href="{{U('Order/index')}}";
														}
													});
												}else{
													alert('请登录后在进行操作');
												}
											}
										});
									}
								}else{
									alert('请对产品类型进行选择');
								}
							});
						})
					</script>
					<div><img src="./Public/home/images/convinced.png" alt="" /></div>
				</div>
			</div>
		</div>
	</div>
	<!--/center-->
	<!--detail-->
	<div id="shop-detail">
		<div class="shop-detail-left">
			<div class="detail-title">
				<a href="#goodsDesc" class="cur">产品详情</a>
				<a href="#goodsParam">规格参数</a>
				<a href="#goodsPack">包装清单</a>
			</div>
			<div id="goodsDesc">
				{{$detailData['detail']}}
			</div>
			<div id="goodsParam">
				<h4>规格参数</h4>
				{{foreach from="$attrData" value="$a"}}
				<div class="param-content">
					<span class="param-content-title">{{$a['taname']}}：</span>
					<span class="param-content-desc">{{$a['gavalue']}}</span>
				</div>
				{{endforeach}}
			</div>
			<div id="goodsPack">
				<div class="goodsPack">包装清单</div>
				<div class="packList">{{$detailData['dlist']}}</div>
			</div>
		</div>
		<div class="shop-detail-right">
			<dl>
				<dt>热销榜单</dt>
				<dd>
					<ul>
						{{foreach from="$oneGoodsData" value="$v"}}
						<li>
							<a href="{{U('Content/index',['gid'=>$v['gid']])}}"><img src="{{$v['pic']}}"/></a>
							<p>
								<a href="{{U('Content/index',['gid'=>$v['gid']])}}">{{$v['gname']}}<br />
									<i>¥{{$v['shopprice']}}</i>
								</a>
							</p>
						</li>
						{{endforeach}}
					</ul>
				</dd>
			</dl>
		</div>
	</div>
	<div id="goods-bar">
		<div class="goods-bar-box">
			<div class="goods-span">
				<img src="{{$goodsData['pic']}}" alt="" />
				<p>
				<strong>{{$goodsData['gname']}}</strong><br />
				{{$goodsData['shopprice']}}<span>元</span>
				</p>
			</div>
			<a href="#goodsDesc" class="hover">产品详情</a>
			<a href="#goodsParam">规格参数</a>
			<a href="#goodsPack">包装清单</a>
			<a href="" class="goods-buy">立即购买</a>
		</div>
	</div>
	<!--/detail-->
	<!--footer-->
	{{include file="../Common/footer"}}
	<!--/footer-->
	</body>
</html>

